<%@page import="cn.yi.newsys.pojo.User"%>
<%@page import="cn.yi.newsys.service.impl.UserServiceImpl"%>
<%@page import="cn.yi.newsys.service.UserService"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta charset="utf-8">
    <title>处理用户注册请求</title>
  </head>
  
  <body>
  	<%
  		// 接收用户的请求数据
  		request.setCharacterEncoding("UTF-8") ;		
  		String userName = request.getParameter("userName") ;
  		String userPass = request.getParameter("userPwd") ;
  		String email = request.getParameter("email") ;
		// 添加业务逻辑层的引用
		UserService userService = new UserServiceImpl() ;
		// 将用户提交的数据封装成 User 对象
		User user = new User(userName,userPass,1,email) ;
		int num = userService.registerUser(user) ;
		if(num == 1){
			// 注册成功
			out.println("<script>alert('注册成功！');location.href='../index.jsp';</script>") ;
		}else if(num == 0){
			// 注册失败
			out.println("<script>alert('注册失败！');location.href='../index.jsp';</script>") ;
		}else if(num == -1){
			// 用户名被占用
			out.println("<script>alert('用户名已存在！');location.href='../index.jsp';</script>") ;
		}
		
		
		
		
		
		
		
		
  	 %>
   
  </body>
</html>
